package com.ironone.mediaplayerdemo;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.widget.Button;
import android.widget.FrameLayout;
import com.ironone.mediaplayerdemo2.R;

public class Frag4 extends Fragment {
	FrameLayout fragContainer;

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

		// Inflate the layout for this fragment
		final View view = inflater.inflate(R.layout.frag_four, container, false);
		fragContainer = (FrameLayout) getActivity().findViewById(R.id.fragContainer);
		Button btn1 = (Button) view.findViewById(R.id.close_button);

		btn1.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {

				AlphaAnimation fadeOutAnimation = new AlphaAnimation(1, 0); // start alpha, end alpha
				fadeOutAnimation.setDuration(500); // time for animation in milliseconds
				fadeOutAnimation.setFillAfter(true); // make the transformation persist
				fadeOutAnimation.setAnimationListener(new AnimationListener() {         
					@Override
					public void onAnimationEnd(Animation animation) {
						getActivity().getSupportFragmentManager().popBackStack();
						fragContainer.setVisibility(View.GONE);
					}

					@Override
					public void onAnimationRepeat(Animation animation) { }

					@Override
					public void onAnimationStart(Animation animation) { }
				});

				fragContainer.setAnimation(fadeOutAnimation);



				//fragContainer.setVisibility(View.INVISIBLE);

				//fragContainer.setVisibility(View.GONE);

				/*Frag1 nextFrag= new Frag1();
				FragmentTransaction fragTransaction = getFragmentManager().beginTransaction();

				fragTransaction.setCustomAnimations(android.R.anim.fade_in, android.R.anim.fade_out);

				fragTransaction.replace(R.id.fragContainer, nextFrag);
				fragTransaction.addToBackStack(null);
				fragTransaction.commit();*/
			}
		});

		return view;
	}	
}
